package b2.scene.fight.skills
{
	import b2.config.Config;
	import b2.config.EnemyConfig;
	import b2.scene.fight.FightScene;
	import b2.scene.fight.TankSprite;
	
	public class Doom extends BasicSkill
	{
		public function Doom(tankId:int, side:int, level:int, skillArgs:Object)
		{
			super(tankId, side, level, skillArgs);
			coolDown = skillArgs.cooldown;
		}
		
		public override function checkSkillTriggerPremise(x:int, y:int, direction:int):Boolean
		{
			var tank:TankSprite = getPlayState().tanks[tankId];
			if (coolDown < 0)
			{
				var message:String = "<font color='#0000FF'>" + tank.tankName + "</font>发动了<font color='#FF0000'>" + skillArgs.name + "</font>";
				FightScene.getInstance().showBottomMessage(message);
				tank.showMessageFlag = false;
				return true;
			}
			else if (!tank.showMessageFlag && coolDown == 6)
			{
				message = "<font color='#0000FF'>" + tank.tankName + "</font><font color='#00AA00'> 5 </font>秒后发动<font color='#FF0000'>" 
							+ skillArgs.name + "</font>"
				FightScene.getInstance().showTopMessage(message);
				tank.showMessageFlag = true;
				return false;
			}
			return false;
			
		}
		
		public override function discharge(x:int, y:int, direction:int):void
		{
			for (var tankIdStr:String in getPlayState().tanks)
			{
				var otherTank:TankSprite = getPlayState().tanks[tankIdStr];
				if (otherTank != null && tankId != otherTank.tankId)
				{
					onHit(otherTank);
				}
			}
			super.discharge(x, y, direction);
		}
		
		protected function onHit(tankOnHit:TankSprite):void
		{
			var areaDemage:int = level < skillArgs.areaDemage.length ? skillArgs.areaDemage[level] : skillArgs.areaDemage[0] * level;
			getPlayState().updateTankStatus(tankOnHit.tankId, tankId, tankOnHit.currentHp, -areaDemage, 0, 0, true);
		}
	}
}